include(CMakeForceCompiler)

set(CMAKE_SYSTEM_NAME Generic)
#set(CMAKE_SYSTEM_VERSION 1)
#set(CMAKE_SYSTEM_PROCESSOR "arm7")

# specify the cross compiler
cmake_force_c_compiler(clang GNU)
cmake_force_cxx_compiler(clang GNU)

set(CMAKE_LINKER clang)
set(CMAKE_ASM_COMPILER arm-elf-as)

# Never lookup programs, or libraries as we are building the kernel itself
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE NEVER)

# NOTE: The integrated as in clang, cannot handle ldr rd, =constant at the moment
#       Therefore we do not use the integrated-as flag, note, if clang enables this
#       as default, we may need to disable the integrated as.
# NOTE: We use soft float abi, otherwise the kernel will crash on the vsprintf
#       function, that will use NEON registers otherwise. We could enable NEON
#       support in the kernel, but it is not necessary at present, and we would
#       need to add FPU register save and restore to the IRQ and cswitch handlers.
set(TOOLCHAIN_ASM_FLAGS  "")
set(TOOLCHAIN_C_FLAGS    "-ccc-host-triple arm-elf -ccc-gcc-name arm-elf-gcc-4.6 -mfloat-abi=soft -nostdinc -fno-builtin -mcpu=cortex-a8 -nostdlib")
set(TOOLCHAIN_LINK_FLAGS "-march=armv7-a -ccc-host-triple arm-elf -ccc-gcc-name arm-elf-gcc-4.6 -mfloat-abi=soft -nostartfiles -mcpu=cortex-a8 -nostdlib")

set(TOOLCHAIN_OBJCOPY arm-elf-objcopy)
set(TOOLCHAIN_AR arm-elf-ar)
set(TOOLCHAIN_RANLIB arm-elf-ranlib)

# The toolchain does not provide a working runtime, we need to resort to the
# compiler RT from the llvm project. This rt directory is not part of SMACK at
# the moment so your build will probably fail at this point.
set(TOOLCHAIN_RT false)
